package com.service.impl;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.springframework.stereotype.Service;

import com.dao.QuatationDao;
import com.service.QuatationService;
import com.utils.MyPage;

@Service
@Transactional
public class QuatationServiceImpl implements QuatationService {

	@Resource
	private QuatationDao quatationDao;

	@Override
	public MyPage getPage(String curPage, String rowPage) {
		int start = 0; // 查询数据下标
		int rows = 0; // 查询数据的行数
		int ncurPage = 0; // 当前页
		// 判断当前页
		if (curPage != null) {
			ncurPage = Integer.parseInt(curPage);
		}
		// 判断行数
		if (rowPage != null) {
			rows = Integer.parseInt(rowPage);
		}
		// 总记录数
		int total = (int) quatationDao.count();
		// 修改行数越界
		if (rows <= 0) {
			rows = 5;
		}
		// 总页数
		int totalPage = (total + rows - 1) / rows;
		// 修改当前页数越界
		if (ncurPage < 0)
			ncurPage = 1;
		if (ncurPage > totalPage)
			ncurPage = totalPage;

		start = (ncurPage - 1) * rows;
		MyPage page = new MyPage();
		page.setTotal(total);
		page.setRows(rows);
		page.setStart(ncurPage);
		page.setList(quatationDao.list(start, rows));
		return page;
	}

}
